package com.myxh.compiler;

import java.util.ArrayList;
import java.util.Stack;


/**
 * 非终结符的分析栈
 * @author yang
 *
 */
class NotaminalStack
{
	public Stack<String> noTaminals = new Stack<String>();	
	public void push(String str)
	{
		noTaminals.push(str);
	}
	
	public void pop()
	{
		noTaminals.pop();
	}
	
	public String toString()
	{
		String str = "";
		for(int i=noTaminals.size()-1; i>=0; i--)
		{
			str += noTaminals.get(i);
		}
		return str;
	}
}


 class SynStepInfo {
	public String step;        //当前分析步数
	public String wordStr;    //当前步骤分析的单词
	public String Noterminal; //当前子程序分析栈
	public String subProgram; //当前子程序
	public String result;    //当前分析结果

	public SynStepInfo(int step, String wordStr, String Noterminal, String subProgram, String result)
	{
		this.step = String.valueOf(step);
		this.wordStr = wordStr;
		this.Noterminal = Noterminal;
		this.subProgram = subProgram;
		this.result = result;
		RecurseAnalysis.step+=1;
	}
	
	public String toString()
	{
		String str = step + "\t" + wordStr + "\t\t" + subProgram + "\t" + Noterminal + "\t" + result; 
		return str;
	}
}

/**
 * 语法分析
 * @author yang
 *
 */
public class RecurseAnalysis {
	 static ArrayList<Word> wordTable;
	 ArrayList<FourElement> FourList = new  ArrayList<FourElement>();
	 public ArrayList<SynStepInfo> stepInfoList = new ArrayList<SynStepInfo>();
	 private  String resultWords = "";
	 NotaminalStack TaminalStack = new NotaminalStack();
	 private Word tempWord = wordTable.get(0);   //当前要分析的单词
	 private int Wordnum = 1;    //已经分析的单词的数量
	 static int step = 0;
	 
	 private void getWord(String subProgram)
	 {
		 if(wordTable.size()>Wordnum)
		 {
			 resultWords = resultWords + " " + tempWord.wordStr;
			 tempWord = wordTable.get(Wordnum);
			 Wordnum+=1;
		 }	 
	 }
	 
	 private void Error(int code, String msg)
	 {
		 stepInfoList.get(Wordnum-1).result = "错误";
		 ErrorInfo err = new ErrorInfo(2,tempWord,msg);
		 ShareData.errors.add(err);
		 skipError(); 
	 }
	 
	 private void skipError()
	 {
		 getWord("skipError()");
		 Wordnum+=1;	 
		 SynStepInfo step =new SynStepInfo(Wordnum, tempWord.wordStr, " ", " ","正确");
		 stepInfoList.add(step);
		 if(tempWord.wordStr.equals("if") ||tempWord.wordStr.equals( "else")||tempWord.wordStr .equals("while") || tempWord.wordStr .equals("for") ||
				 tempWord.wordStr.equals("int")|| tempWord.wordStr.equals("char") || tempWord.wordStr.equals("bool") ||
				 tempWord.type == WordType.IDENTIFIER ||tempWord.wordStr.equals("printf") || tempWord.wordStr.equals("scanf"))
		 {
			 A(); 
		 }
		 if(tempWord.wordStr.equals("#") ||Wordnum>=wordTable.size())
		 {
			 return;
		 }
		 else
		 {
			 step.subProgram = "跳过";
			 step.result = "错误";
			 skipError();
		 }
	 }
	 
	 public String Synanalysis()
	 { 
		 switch(tempWord.wordStr)
		 {
		 case "void": 
			 TaminalStack.push("S");
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "S()","正确"));
			 S();
			 TaminalStack.pop();
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "S()","正确"));
			 break;
		default:
			Error(10,"不能识别的语句开始?");
		 } 
		if(ShareData.errors.size()<=0)
		{
			String result = new String("");	
			result += "步数" + "\t" + "分析的单词" + "\t" + "子程序" + "\t" + "子程序分析栈" + "\t" + "结果\n";
			for(int i=0; i<stepInfoList.size();i++)
			{
				result +=stepInfoList.get(i).toString() + "\n";	
			}
			return result;
		}
		else return "语法分析未通过";
		
	 }
	 
	 private void S()           //开始非终结符//
	 {
		switch(tempWord.wordStr)
		{
			case "void":
				getWord("S()");
				if(tempWord.wordStr.equals("main"))
				{ 
					stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "S()","正确"));
					getWord("S()");
					if(tempWord.wordStr .equals( "("))
					{						 
						stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "S()","正确"));
						getWord("S()");
						if(tempWord.wordStr .equals( ")"))
						{							 
							stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "S()","正确"));
							getWord("S()");
							if(tempWord.wordStr.equals("{"))
							{								 
								stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "S()","正确"));
								getWord("S()");
								TaminalStack.push("A");
								stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "S()","正确"));
								A();
								TaminalStack.pop();
								stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "S()","正确"));
								if(tempWord.wordStr.equals("}"))
								{									 
									stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "S()","正确"));
									getWord("S()");
									if(tempWord.wordStr .equals( "#"))
									{										 
										stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "S()","正确"));
										return;
									}
								}
								else{ Error(4, "main函数缺少右大括号");     }
							}
							else{ Error(4, "main函数缺少左大括号");     }
						}
						else
						{
							Error(4, "main函数缺少右括号");
						}
					}
					else
					{
						Error(3, "main后跟左括号");
					}
				}
				else
				{
					Error(2, "main拼写错误");
				}
				break;
				
			case "#":
				break;
			default :
				Error(0,"找不到程序入口");
				break;
		}
	 }
	 
	
	 private void A()
	 {
		if(tempWord.type == WordType.IDENTIFIER)
		{
			TaminalStack.push("C");
			stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "A()","正确"));
			C();
			TaminalStack.pop();
			stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "A()","正确"));
			TaminalStack.push("A");
			A();
			TaminalStack.pop();
			stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "A()","正确"));
			return;
		}
		 
		 switch(tempWord.wordStr)
		 {
			 case "int":
			 case "char":
			 case "bool":
			 case "if":
			 case "else":
			 case "for":
			 case "while":
			 case "scanf":
			 case "printf":
				TaminalStack.push("C");
				stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "A()","正确"));
				C();
				TaminalStack.pop();
				stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "A()","正确"));
				TaminalStack.push("A");
				A();
				TaminalStack.pop();
				stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "A()","正确"));
				break;
			 case "#":
				 break;
			default:
				break;
		 } 
	 }
	 
	 
	 private void C()
	 {
		 if(tempWord.type == WordType.IDENTIFIER)
			{
				 TaminalStack.push("R");
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "C()","正确"));
					R();
				TaminalStack.pop();
				stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "C()","正确"));
					return;
			}
		 switch(tempWord.wordStr)
		 {
			 case "int":
			 case "char":
			 case "bool":
				 TaminalStack.push("X");
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "C()","正确"));
				 X();
				 TaminalStack.pop();
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "C()","正确"));
				break;
			 case "if":
			 case "else":
			 case "for":
			 case "while":
			 case "scanf":
			 case "printf":
				 TaminalStack.push("B");
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "C()","正确"));
				 B();
				 TaminalStack.pop();
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "C()","正确"));
				 break;
			 case "#":
				 break;
			default:
				Error(5,"不能识别");
				break;
		 } 
	 }
	 
	 private void R()
	 {
		 if(tempWord.type == WordType.IDENTIFIER)
		 {			 
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "R()","正确"));
			 getWord("R()");
			 if(tempWord.wordStr .equals( "="))
			 {			 
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "R()","正确"));
				 getWord("R()");
				 TaminalStack.push("L");
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "R()","正确"));
				 L();
				 TaminalStack.pop();
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "R()","正确"));
				 
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "R()","正确"));
				 getWord("R()");
				 if(tempWord.wordStr.equals(";"))
				 {				 
					 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "R()","正确"));
					 getWord("R()");
					return; 
				 }
			 }
			 else Error(6,"变量赋值语句错误");
		 }
	 }
	 
	 private void L()
	 {
		 TaminalStack.push("T");
		 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "L()","正确"));
		 T();
		 TaminalStack.pop();
		 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "L()","正确"));
		 TaminalStack.push("L1");
		 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "L()","正确"));
		 L1();
		 TaminalStack.pop();
		 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "L()","正确"));	
	 }
	 
	 private void L1()
	 {
		 if(tempWord.type == WordType.IDENTIFIER || tempWord.type == WordType.INT_CONST)
		 {
			return;
		 }
		 else
		 {
			 switch(tempWord.wordStr)
			 {
				 case "(":
					 break;
				 case "+":
				 case "-":					 
					 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "L1()","正确"));
					 getWord("L1()");
					 TaminalStack.push("L");
					 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "L1()","正确"));
					 L();
					 TaminalStack.pop();
					 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "L1()","正确"));	
					 break;
				 case "#":
					 break;
				 default:
					break;
			 } 
		 }
	 }
	 
	 private void T()
	 {
		 TaminalStack.push("F");
		 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "T()","正确"));
		 F();
		 TaminalStack.pop();
		 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "T()","正确"));	
		 TaminalStack.push("T1");
		 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "T()","正确"));
		 T1();
		 TaminalStack.pop();
		 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "T()","正确"));	
		  
	 }
	 
	 private void T1()
	 { 
		 if(tempWord.type==WordType.IDENTIFIER||tempWord.type==WordType.INT_CONST||
				 tempWord.type==WordType.CHAR_CONST)
		 {
			 return;
		 }
		 else
		 {
			 switch(tempWord.wordStr)
			 {
			 case "*":
			 case "/":				 
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "T1()","正确"));
				 getWord("T1()");
				 TaminalStack.push("T");
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "T1()","正确"));
				 T();
				 TaminalStack.pop();
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "T1()","正确"));
				 break;
			 case "(":
			 case "#":
				 break;
				 default:
					 break;
			 }
		 } 
	 }
	 private void F()
	 {
		 if(tempWord.wordStr .equals( "("))
		 {	 
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "F()","正确"));
			 getWord("F()");
			 TaminalStack.push("L");
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "F()","正确"));
			 L();
			 TaminalStack.pop();
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "F()","正确"));
			 if( tempWord.wordStr .equals( ")") )
			 {	 
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "F()","正确"));
				 getWord("F()");
				 return;
			 }
			 else 
			 {
				 Error(9,"缺少右括�?"); 
				 return;
			 }
		 }  
		 else 
		 {
			 switch(tempWord.type)
			 {
			 case IDENTIFIER:
			 case INT_CONST:
			 case CHAR_CONST:				 
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "F()","正确"));
				 getWord("F()");
				 break;
			 default:
				 Error(8,"类型错误");
				 break;
			 }	
		 }
		
	 }
	 
	 
	 private void B()
	 {
		switch(tempWord.wordStr)
		{
		case "printf":		 
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
			getWord("B()");
			if(tempWord.wordStr .equals( "("))
			{				 
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
				 getWord("B()");
				TaminalStack.push("P");
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
				 P();
				TaminalStack.pop();
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
				getWord("B()");
				if(tempWord.wordStr .equals( ")"))
				{				 
					 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));	
					 getWord("B()");
					if(tempWord.wordStr .equals( ";"))
					{		 
						 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
						 getWord("B()");
						break;
					}
					else Error(11,"语句末尾缺少分号");
				}
			}
			break;
		case "scanf":			 
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
			 getWord("B()");
			if(tempWord.wordStr .equals( "("))
			{				 
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
				 getWord("B()");
				if(tempWord.type == WordType.IDENTIFIER)
				{					 
					 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
					 getWord("B()");
					if(tempWord.wordStr .equals( ")"))
					{						 
						 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
						 getWord("B()");
						if(tempWord.wordStr .equals(";"))
						{						 
							 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
							 getWord("B()");
							break;
						}
					}
				}
				
			}
			break;
		case "if":		 
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
			 getWord("B()");
			if(tempWord.wordStr.equals("("))
			{		 
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
				 getWord("B()");
				TaminalStack.push("E");
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
				 E();
				TaminalStack.pop();
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
				 if(tempWord.wordStr.equals(")"))
				{		 
					 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
					 getWord("B()");
					if(tempWord.wordStr.equals("{"))
					{					 
						 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
						 getWord("B()");
						TaminalStack.push("A");
						 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
						 A();
						TaminalStack.pop();
						 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
						 if(tempWord.wordStr.equals("}"))
						{							 
							 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
							 getWord("B()");
							if(tempWord.wordStr.equals("else"))
							{								 
								 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
								 getWord("B()");
								if(tempWord.wordStr.equals("{"))
								{									 
									 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
									 getWord("B()");
									TaminalStack.push("A");
									 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
									 A();
									TaminalStack.pop();
									 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
									 if(tempWord.wordStr.equals("}"))
									{										 
										 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
										 getWord("B()");
										return;
									}
								}
							}
							else 
							{
								TaminalStack.push("A");
								 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
								 A();
								TaminalStack.pop();
								 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
							}		
						}
					}
					
				}
				
			}
				
		case "while":
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
			 getWord("B()");
			if(tempWord.wordStr .equals( "("))
			{	 
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
				 getWord("B()");
				TaminalStack.push("E");
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
				 E();
				TaminalStack.pop();
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
				 if(tempWord.wordStr .equals(")"))
				{
					 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
					 getWord("B()");
					if(tempWord.wordStr .equals( "{"))
					{				 
						 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
						 getWord("B()");
						TaminalStack.push("A");
						 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
						 A();
						TaminalStack.pop();
						 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
						 getWord("B()");
						if(tempWord.wordStr .equals( "}"))
						{
		
							break;
						}
					}
				}
				
			}
			break;
		case "for":
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
			 getWord("B()");
			if(tempWord.wordStr .equals( "("))
			{
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
				 getWord("B()");
				TaminalStack.push("Z");
				TaminalStack.push("Y");
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
				 Y();
				TaminalStack.pop();
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
				 Z();
				TaminalStack.pop();
				 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
				 if(tempWord.wordStr .equals( ";"))
					{
					 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
					 getWord("B()");
						TaminalStack.push("G");
						 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
						 G();
						TaminalStack.pop();
						 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
						 if(tempWord.wordStr .equals( ";"))
						{
							 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
							 getWord("B()");
							TaminalStack.push("Q");
							 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
							 Q();
							TaminalStack.pop();
							 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
							 if(tempWord.wordStr .equals( ")"))
							{
								 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
								 getWord("B()");
								if(tempWord.wordStr .equals( "{"))
								{
									 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
									 getWord("B()");
									TaminalStack.push("A");
									 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
									 A();
									TaminalStack.pop();
									 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "B()","正确"));
									 if(tempWord.wordStr .equals( "}"))
									{
										stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "A()","正确"));
										getWord("B()");
										break;
									}
								}
							}
						}
						
					}
					
			}
			
			default:
				Error(12,"错误的语句开始");
			
		}
	
	 }
	 
	 private void Q()
	 {
		 if(tempWord.type == WordType.IDENTIFIER)
		 {
			stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "Q()","正确"));						
			 getWord("Q()");
			 TaminalStack.push("O");
			stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "Q()","正确"));						
			 O();
		    TaminalStack.pop();
			stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "Q()","正确"));						

		 }
	 }
	 
	 private void O()
	 {
		 switch(tempWord.wordStr)
		 {
		 case "++":
		 case "--":
		 case "#":	 
		stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "O()","正确"));									 
		 getWord("O()");
		 break;
		 default:
			 Error(15, "错误的表达式");
		 }
		 
	 }
	 
	 private void Y()
	 {
		 switch(tempWord.wordStr)
		 {
		 case "int":
		 case "char":
		 case "bool":  
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "Y()","正确"));
			 getWord("Y()");
			 break;
			 default :
				 Error(15,"错误的数据类型");
		 }
		 
	 }
	 
	 private void Z()
	 {
		 TaminalStack.push("Z1");
		 TaminalStack.push("U");
		 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "Z()","正确"));
		U();
		TaminalStack.pop();
		stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "Z()","正确"));
		Z1(); 
		TaminalStack.pop();
		stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "Z()","正确"));
	 }
	 
	 private void G()
	 {
		 if(tempWord.type==WordType.IDENTIFIER||tempWord.type==WordType.INT_CONST||
				 tempWord.type==WordType.CHAR_CONST)
		 {
			 TaminalStack.push("F");
			 TaminalStack.push("D");
			 TaminalStack.push("F");
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "G()","正确"));
			F();
			TaminalStack.pop();
			stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "G()","正确"));
			D();
			TaminalStack.pop();
			stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "G()","正确"));
			F();
			TaminalStack.pop();
			stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "G()","正确"));
		 } 
		 switch(tempWord.wordStr)
		 {
		 case "(":
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "G()","正确"));
			 getWord("G()");
			 TaminalStack.push("E");
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "G()","正确"));
			 E();
			 TaminalStack.pop();
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "G()","正确"));			 
			 getWord("G()");
			 if(tempWord.wordStr .equals( ")"))
			 {
				 break;
			 }
			 else 
			 {
				 Error(18,"缺少右括�?");
			 }
			 break;
		 case "!":
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "G()","正确"));			 			 
			 getWord("G()");
			 TaminalStack.push("E");
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "G()","正确"));
			 E();
			 TaminalStack.pop();
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "G()","正确"));
			 break;
			 default:
				break;
		 }
	 }
	 
	 private void D()
	 {
		 switch(tempWord.wordStr)
		 {
		 case "<":
		 case ">":
		 case "++":
		 case "!+":	  
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "D()","正确"));
			 getWord("D()");
			 break;
			 default:
				 break;
		 }
	 }
	 
	 private void E()
	 {
		 TaminalStack.push("E1");
		 TaminalStack.push("H");
		 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "E()","正确"));
		H();
		TaminalStack.pop();
		stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "E()","正确"));
		E1();
		TaminalStack.pop();
		stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "E()","正确"));
	 }
	 
	 private void E1()
	 {
		 if(tempWord.wordStr.equals("&&"))
		 {		  
			stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "E1()","正确"));
			 getWord("E1()");
			 TaminalStack.push("E");
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "E1()","正确"));
			 E();
			 TaminalStack.pop();
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "E1()","正确"));
		 }
	 }
	 
	 private void H()
	 {
		 TaminalStack.push("H1");
		 TaminalStack.push("G");
		 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "H()","正确"));
		G();
		TaminalStack.pop();
		stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "H()","正确"));
		H1();
		TaminalStack.pop();
		stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "H()","正确"));
	 }
	 
	 private void H1()
	 {
		 if(tempWord.wordStr.equals("|"))
		 {
			stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "H1()","正确"));
			 getWord("E1()");
			 TaminalStack.push("H");
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "H1()","正确"));
			 H();
			 TaminalStack.pop();
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "H1()","正确"));
		 }
		
	 }
	 
	 private void P()
	 {
		 switch (tempWord.type)
			{
			case IDENTIFIER:
			case CHAR_CONST:
			case INT_CONST:
				break;
			default :
				Error(18, "不能输出该类�?");
			} 
	 }
	 
	 private void U()
	 {
		 if(tempWord.type == WordType.IDENTIFIER)
		 {
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "U()","正确"));
			 getWord("U()");
			 TaminalStack.push("U1");
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "U()","正确"));
			 U1();
			 TaminalStack.pop();
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "U()","正确"));
		 }
	 }
	 
	 private void U1()
	 {
		 switch (tempWord.wordStr)
		 {
		 case "=":
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "U1()","正确"));
			 getWord("U1()");
			 TaminalStack.push("L");
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "U1()","正确"));
			 L();
			 TaminalStack.pop();
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "U1()","正确"));
			 break;
		 case "#":
			 break;
		  default :
			  break;
		 }
	 }
	 
	 private void Z1()
	 {
		 switch (tempWord.wordStr)
		 {
		 case ",":
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "Z1()","正确"));
			 getWord("Z1()");
			 TaminalStack.push("Z");
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "Z1()","正确"));
			 Z();
			 TaminalStack.pop();
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "Z1()","正确"));
			 break;
		 case "#":
			 break;
		  default :
			  break;
		 } 
	 }
	 
	 
	 private void X()
	 {
		 TaminalStack.push("Z");
		 TaminalStack.push("Y");
		 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "X()","正确"));
		 Y();
		 TaminalStack.pop();
		 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "X()","正确"));
		 Z();
		 TaminalStack.pop();
		 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "X()","正确"));
		 if(tempWord.wordStr.equals(";"))
		 { 
			 stepInfoList.add(new SynStepInfo(step, tempWord.wordStr, resultWords+TaminalStack.toString(), "X()","正确"));
			 getWord("X()");
			 return;
		 }
	 }
	  
	 
	 public  Boolean isSucceed()
	 {
		return ShareData.errors.size()==0;
	 }


}
